<?php use_stylesheet('jquery.treeview.css') ?>
<?php use_javascript('fg.menu.js')?>
<?php use_javascript('tree_menus.js')?>
<?php use_helper('jQuery')?>

<div id="tree_structure">
<ul id="treeview" class="filetree">
    <li id="<?php echo 'portal_'.$portal->getId()?>" class="open">
        <span class="folder">
            <?php if($sf_user->hasCredential('Ver portal')): ?>
                <?php echo jq_link_to_remote(
                        $portal->getTitle(),
                        array(
                            'update' => 'main',
                            'url'    => url_for('portal_show',$portal),
                            'before' => 'clearView();showLoaderMain();',
                            'complete' => 'hideLoader();',
                            'script' => true
                        )) ?>
            <?php else: ?>
                <?php echo $portal->getTitle() ?>
            <?php endif; ?>
            <a id="portal_menu" tabindex="0" href="#portal_menu_options"
                class="ui-button ui-widget ui-state-default ui-corner-all ui-button-icons-only"
                aria-disabled="false" title="Opciones">
                <span class="ui-button-icon-primary ui-icon ui-icon-circle-plus"></span>
                <span class="ui-button-text">Opciones</span>
                <span class="ui-button-icon-secondary ui-icon ui-icon-triangle-1-s"></span>
            </a>
            <div id="portal_menu_options" class="ui-helper-hidden-accessible">
                <ul id="<?php echo 'portal_sections'?>">
                    <?php if($sf_user->hasCredential('Ver portal')): ?>
                        <li>
                            <?php echo jq_link_to_remote(
                                '<span class="menu-bullet ui-icon ui-icon-bullet"></span> Ver',
                                array(
                                    'update' => 'main',
                                    'url'    => url_for('portal_show',$portal),
                                    'before' => 'clearView();showLoaderMain();',
                                    'complete' => 'hideLoader();',
                                    'script' => true
                                )) ?>
                        </li>
                    <?php endif; ?>
                    <?php if($sf_user->hasCredential('Editar portal')): ?>
                        <li>
                            <?php echo jq_link_to_remote(
                                '<span class="menu-bullet ui-icon ui-icon-bullet"></span> Editar',
                                array(
                                    'update' => 'main',
                                    'url'    => url_for('portal_edit',$portal),
                                    'before' => 'clearView();showLoaderMain();',
                                    'complete' => 'hideLoader();',
                                    'script' => true
                                )) ?>
                        </li>
                    <?php endif; ?>
                    <?php if($sf_user->hasCredential('Habilitar boton de servicio')): ?>
                        <li>
                            <?php echo jq_link_to_remote('<span class="ui-icon ui-icon-bullet" style="float: left"></span>'.
                                ($portal->getUsesServButtons() ? 'Deshabilitar' : 'Habilitar').' botones de servicio',
                                array(
                                    'update' => 'ajax_holder_for_multi_update',
                                    'url'    => url_for('portal_toggle_servbuttons',$portal),
                                    'before' => 'clearTree();showLoaderTree();',
                                    'complete' => 'createTree();activateTreeMenu();hideLoader();',
                                    'script' => true
                                )) ?>
                        </li>
                    <?php endif; ?>
                    <?php if($sf_user->hasCredential('Crear sección')): ?>
                    <li>
                        <?php echo jq_link_to_remote(
                            '<span class="ui-icon ui-icon-bullet" style="float: left"></span> Crear Sección Galeria',
                            array(
                                'update' => 'main',
                                'url'    => url_for('section_newsection',$portal).'?type=Gallery',
                                'before' => 'clearView();showLoaderMain();',
                                'complete' => 'hideLoader();',
                                'script' => true
                            )) ?>
                    </li>
                    <li>
                        <?php echo jq_link_to_remote(
                            '<span class="ui-icon ui-icon-bullet" style="float: left"></span> Crear Sección Noticias',
                            array(
                                'update' => 'main',
                                'url'    => url_for('section_newsection',$portal).'?type=News',
                                'before' => 'clearView();showLoaderMain();',
                                'complete' => 'hideLoader();',
                                'script' => true
                            )) ?>
                    </li>
                    <li>
                        <?php echo jq_link_to_remote(
                            '<span class="ui-icon ui-icon-bullet" style="float: left"></span> Crear Sección Vacia',
                            array(
                                'update' => 'main',
                                'url'    => url_for('section_newsection',$portal).'?type=Flat',
                                'before' => 'clearView();showLoaderMain();',
                                'complete' => 'hideLoader();',
                                'script' => true
                            )) ?>
                    </li>
                    <li>
                        <?php echo jq_link_to_remote(
                            '<span class="ui-icon ui-icon-bullet" style="float: left"></span> Crear Sección Descargas',
                            array(
                                'update' => 'main',
                                'url'    => url_for('section_newsection',$portal).'?type=Download',
                                'before' => 'clearView();showLoaderMain();',
                                'complete' => 'hideLoader();',
                                'script' => true
                            )) ?>
                    </li>
                    <?php endif; ?>
                    <?php if($portal->getUsesContentComments()): ?>
                        <?php if($sf_user->hasCredential('Listar comentarios')): ?>
                            <li>
                                <?php echo jq_link_to_remote(
                                    '<span class="ui-icon ui-icon-bullet" style="float: left"></span> Mostrar todos los comentarios',
                                    array(
                                        'update' => 'main',
                                        'url'    => url_for('portal_comments',$portal),
                                        'before' => 'clearView();showLoaderMain();',
                                        'complete' => 'hideLoader();',
                                        'script' => true
                                    ), array(
                                        'title' => 'Comentarios realizados sobre los contenidos de este portal.'
                                    ))?>
                            </li>
                        <?php endif; ?>
                    <?php endif; ?>
                </ul>
            </div>
        </span>
        <ul id="<?php echo 'sections_portal_'.$portal->getId()?>">
            <?php if($sf_user->hasCredential('Listar headers')): ?>
                <li class="closed">
                    <span class="folder">
                        <?php if($sf_user->hasCredential('Ver header')): ?>
                            <?php echo jq_link_to_remote(
                                    'Header',
                                    array(
                                        'update'   =>   'main',
                                        'url'      =>   url_for('portal_header_show',$portal->getHeader()),
                                        'before' => 'clearView();showLoaderMain();',
                                        'complete' => 'hideLoader();',
                                        'script' => true
                                    ))?>
                        <?php else: ?>
                            Header
                        <?php endif; ?>
                        <a id="header_menu" tabindex="0" href="#header_menu_options"
                            class="ui-button ui-widget ui-state-default ui-corner-all ui-button-icons-only"
                            aria-disabled="false" title="Opciones">
                            <span class="ui-button-icon-primary ui-icon ui-icon-circle-plus"></span>
                            <span class="ui-button-text">Opciones</span>
                            <span class="ui-button-icon-secondary ui-icon ui-icon-triangle-1-s"></span>
                        </a>
                        <div id="header_menu_options" class="ui-helper-hidden-accessible">
                            <ul>
                                <?php if($sf_user->hasCredential('Ver header')): ?>
                                    <li>
                                        <?php echo jq_link_to_remote(
                                            '<span class="ui-icon ui-icon-bullet" style="float: left"></span> Ver',
                                            array(
                                                'update' => 'main',
                                                'url'    => url_for('portal_header_show',$portal->getHeader()),
                                                'before' => 'clearView();showLoaderMain();',
                                                'complete' => 'hideLoader();',
                                                'script' => true
                                            ), array(
                                                'title' => 'Detalles del header.'
                                            ))?>
                                    </li>
                                <?php endif; ?>
                            </ul>
                        </div>
                    </span>
                    <ul>
                        <?php foreach ($portal->getHeader()->getElements() as $element): ?>
                            <li>
                                <?php echo jq_link_to_remote(
                                    $element,
                                    array(
                                        'update' => 'main',
                                        'url'    => url_for('element_show', $element),
                                        'before' => 'clearView();showLoaderMain();',
                                        'complete' => 'hideLoader();',
                                        'script' => true
                                    ))?>
                            </li>
                        <?php endforeach;?>
                    </ul>
                </li>
            <?php endif; ?>
            <?php if($sf_user->hasCredential('Listar footers')): ?>
                <li class="closed">
                    <?php if($sf_user->hasCredential('Ver footer')): ?>
                    <span class="folder">
                        <?php echo jq_link_to_remote(
                                'Footer',
                                array(
                                    'update' => 'main',
                                    'url'    => url_for('portal_footer_show',$portal->getFooter()),
                                    'before' => 'clearView();showLoaderMain();',
                                    'complete' => 'hideLoader();',
                                    'script' => true
                                )) ?>
                        <?php else: ?>
                            Footer
                        <?php endif; ?>
                        <a id="footer_menu" tabindex="0" href="#footer_menu_options"
                            class="ui-button ui-widget ui-state-default ui-corner-all ui-button-icons-only"
                            aria-disabled="false" title="Opciones">
                            <span class="ui-button-icon-primary ui-icon ui-icon-circle-plus"></span>
                            <span class="ui-button-text">Opciones</span>
                            <span class="ui-button-icon-secondary ui-icon ui-icon-triangle-1-s"></span>
                        </a>
                        <div id="footer_menu_options" class="ui-helper-hidden-accessible">
                            <ul>
                                <?php if($sf_user->hasCredential('Ver footer')): ?>
                                    <li>
                                        <?php echo jq_link_to_remote(
                                            '<span class="ui-icon ui-icon-bullet" style="float: left"></span> Ver',
                                            array(
                                                'update' => 'main',
                                                'url'    => url_for('portal_footer_show',$portal->getFooter()),
                                                'before' => 'clearView();showLoaderMain();',
                                                'complete' => 'hideLoader();',
                                                'script' => true
                                            ),array(
                                                'title' => 'Detalles del footer.'
                                            ))?>
                                    </li>
                                <?php endif; ?>
                                <?php if($sf_user->hasCredential('Editar footer')): ?>
                                    <li>
                                        <?php echo jq_link_to_remote(
                                            '<span class="ui-icon ui-icon-bullet" style="float: left"></span> Editar',
                                            array(
                                                'update' => 'main',
                                                'url'    => url_for('portal_footer_edit',$portal->getFooter()),
                                                'before' => 'clearView();showLoaderMain();',
                                                'complete' => 'hideLoader();',
                                                'script' => true
                                            ), array(
                                                'title' => 'Detalles del footer.'
                                            ))?>
                                    </li>
                                <?php endif; ?>
                            </ul>
                        </div>
                    </span>
                    <ul>
                        <?php foreach ($portal->getFooter()->getElements() as $element): ?>
                            <li>
                                <?php echo jq_link_to_remote(
                                    $element,
                                    array(
                                        'update' => 'main',
                                        'url'    => url_for('element_show', $element),
                                        'before' => 'clearView();showLoaderMain();',
                                        'complete' => 'hideLoader();',
                                        'script' => true
                                    ))?>
                            </li>
                        <?php endforeach;?>
                    </ul>
                </li>
            <?php endif; ?>
            <?php if($portal->getUsesServButtons() && $sf_user->hasCredential('Listar botones de servicio')):?>
                <li class="closed">
                    <span class="folder">Botones de Servicio</span>
                    <ul>
                        <?php foreach ($portal->getServiceButtons() as $button): ?>
                            <?php if($button->getType()->getType() !== 'SMS'): ?>
                                <li>
                                    <?php echo jq_link_to_remote(
                                        $button->getType(),
                                        array(
                                            'update' => 'main',
                                            'url'    => url_for('servicebutton_show', $button),
                                            'before' => 'clearView();showLoaderMain();',
                                            'complete' => 'hideLoader();',
                                            'script' => true
                                        )) ?>
                                </li>
                            <?php else: ?>
                                <li>
                                    SMS (Muy pronto)
                                </li>
                            <?php endif; ?>
                        <?php endforeach;?>
                    </ul>
                </li>
            <?php endif;?>
            <?php if($sf_user->hasCredential('Listar secciones')): ?>
                <?php include_partial('portal/tree',
                        array('sections' => $portal->getTopSections(),
                            'uses_comments' => $portal->getUsesContentComments()
                        ))?>
            <?php endif; ?>
        </ul>
    </li>
</ul>
</div>
<div id="treecontrols">
    <a title="Cerrar todos" href="#"
       class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-primary">
        <span class="ui-button-icon-primary ui-icon ui-icon-circle-minus"></span>
        <span class="ui-button-text">Cerrar</span>
    </a>
    <a title="Expandir todos" href="#"
       class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-primary">
        <span class="ui-button-icon-primary ui-icon ui-icon-circle-plus"></span>
        <span class="ui-button-text">Expandir</span>
    </a>
</div>